﻿<cfsilent>
	<cfscript>
		
		event.setArg("pageTitle", "平台管理团队 - 调整用户组");
		
		targetArgs = structNew();
		
		userId = event.getArg("uid");
		
		sql = "SELECT a.group_id, a.group_name, a.group_desc  
				FROM t_group a  
				WHERE a.is_manager = '1' 
				ORDER BY a.group_id ASC";
				
		queryObj = new Query(datasource = application.dnsSlave);
		rs_group = queryObj.execute(sql=sql).getResult();
		
		sql = "SELECT a.user_name, a.user_id, a.user_email  
				FROM t_user a  
				where a.user_id = :userId";
				
		queryObj = new Query(datasource = application.dnsSlave);
		queryObj.addParam(name="userId", value=userId, cfsqltype="cf_sql_varchar");
		
		rs_user = queryObj.execute(sql=sql).getResult();
		
		sql = "SELECT b.group_id,b.group_name,b.group_desc
				FROM t_groupuser a  
					 INNER JOIN t_group b ON b.group_id = a.group_id 
				WHERE a.user_id = :userId";
				
		queryObj = new Query(datasource = application.dnsSlave);
		queryObj.addParam(name="userId", value=userId, cfsqltype="cf_sql_varchar");
		
		rs_userGroup = queryObj.execute(sql=sql).getResult();
		

		userGroupHas = [];
		
		for ( a=1; a LTE rs_userGroup.recordCount; a++) {
			arrayAppend( userGroupHas, [rs_userGroup["group_id"][1],rs_userGroup["group_name"][1],rs_userGroup["group_desc"][1]] );
		}

	</cfscript>
</cfsilent>

<div id="headArea">
	<div class="uiHeader uiHeaderWithImage ptm">
		<div class="clearfix uiHeaderTop">
			<div class="uiHeaderActions rfloat">
				<a class="uiButton" href="<cfoutput>#buildURL('groupUser')#</cfoutput>"><i class="mrs img btnList"></i><span class="uiButtonText">管理团队</span></a>
			</div>
			<div>
				<h2 class="uiHeaderTitle">
					<cfif rs_userGroup.recordCount>
						<i class="uiHeaderImage img icon16x16 edit"></i>调整用户权限
						<cfelse>
						<i class="uiHeaderImage img icon16x16 application"></i>创建用户授权
					</cfif>
				</h2>
			</div>
		</div>
	</div>
</div>

<div class="UIElement">

	<ul class="groupUser">
		<li>
			<div class="clearfix">
				<div class="UISmallUserCard">
					<div class="cardContent">
						<img class="img" src="<cfoutput>#getProperty('cdnServer')#</cfoutput><cfoutput>#getContextRoot()#</cfoutput>/acadmicRes/assets/graphic/userSmall.png" style="background-image: url('<cfoutput>#getContextRoot()#</cfoutput>/acadmicManager/teacher/portrait/<cfoutput>#rs_user["user_id"][1]#</cfoutput>.jpg');">
						<div class="cardDetail">
							<h3><cfoutput>#rs_user["user_name"][1]# <span class="uid">(#rs_user["user_id"][1]#)</span></cfoutput></h3>
							<p><cfoutput>#rs_user["user_email"][1]#</cfoutput></p>
						</div>
					</div>
				</div>
			</div>
		</li>
	</ul>
	
	<div class="UItab">
		<div class="tabLables">
			<span tabTarget="authorizedGroup">所在用户组</span>
		</div>
	</div>

	<div id="authorizedGroup" class="tabContentBox">

		<cfif rs_userGroup.recordCount>
			<cfset structInsert(targetArgs, "uid", rs_user["user_id"][1], true) />
			
			<table class="UIEditable">
				<cfset idx = 0 />
			
                <cfloop query="rs_userGroup" >
					<cfset idx ++ />
					<cfset structInsert(targetArgs, "gid", rs_userGroup.group_id, true) />
					<tr>
						<td width="20"><i class="auth <cfoutput>#rs_userGroup.group_id#</cfoutput>"></i></td>
						<td width="200"><cfoutput>#rs_userGroup.group_name#</cfoutput></td>
						<td><cfoutput>#rs_userGroup.group_desc#</cfoutput></td>
						<td width="20">
							<cfif left(rs_userGroup.group_id,1) neq "P" and mid(rs_userGroup.group_id, 2, 1) neq "D">
								<a class="stat delete" href="<cfoutput>#buildURL('userGroupRevoke', targetArgs)#</cfoutput>"></a>
							</cfif>
						</td>
					</tr>
				</cfloop>
			</table>
		</cfif>
	</div>
	
	<div class="UItab">
		<div class="tabLables">
			<span tabTarget="authorizedGroup">可授权用户组</span>
		</div>
	</div>
	
	
	<div id="systemGroup" class="tabContentBox">
		<table class="UIEditable">
			<cfset idx = 0 />
		
            <cfloop query="rs_group" >
				<cfif mid(rs_group.group_id, 2,1) neq "D" and ( not arrayFind(userGroupHas, rs_group.group_id) )>
					<cfset idx ++ />
					<cfset structInsert(targetArgs, "gid", rs_group.group_id, true) />
					<tr>
						<td width="20"><i class="auth <cfoutput>#rs_group.group_id#</cfoutput>"></i></td>
						<td width="200"><cfoutput>#rs_group.group_name#</cfoutput></td>
						<td><cfoutput>#rs_group.group_desc#</cfoutput></td>
						<td width="20"><a class="stat checked" href="<cfoutput>#buildURL('userGroupGrant', targetArgs)#</cfoutput>"></a></td>
					</tr>
				</cfif>
			</cfloop>
		</table>
	</div>
	
</div>
